package phone.qyg.com.qyg.activity;

import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.TextView;

import com.app.base.tool.BaseActivity;
import com.app.utils.CommonUtil;
import com.app.utils.TxtUtils;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import phone.qyg.com.qyg.R;
import phone.qyg.com.qyg.model.Base;

/**
 * 作者：lblbh on 2018/1/19 10:54
 * 邮箱：lanbuhan@163.com
 * 功能：阅读文本txt
 */
@ContentView(R.layout.culture_file_txt_detail)
public class CultureFileTxtActivity extends BaseActivity {

    @ViewInject(R.id.back)
    TextView back;

    @ViewInject(R.id.item_content)
    TextView item_content;

    Base model;

    @Override
    public void initSucessView() {
        Object obj = (Base) getTransModels();

        if(obj instanceof Base){
            model = (Base) obj;
        }
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        back.setText(setAttributeText(model.title));

        TxtUtils.httpTxtContent(model.url,
                new TxtUtils.OnFileStr() {
                    @Override
                    public void onFileStr(final String result) {
                        CommonUtil.runOnUIThread(new Runnable() {
                            @Override
                            public void run() {
                                CommonUtil.textViewSetText(item_content,result);
                            }
                        });
                    }
                });
    }


    @Event(value = {R.id.back})
    private void viewOnClick(View v){
        switch (v.getId()){
            case R.id.back:
                this.finish();
                break;
        }
    }

    @Override
    public void initViewHandler() {
        if(null != item_content)
            item_content.setMovementMethod(ScrollingMovementMethod.getInstance());
    }
}
